YF <- readRDS("../data_clean/YFcases/YFlong.rds")
brazil <- readOGR("../data_processingScripts/municipios_2010", "municipios_2010")
## OGR data source with driver: ESRI Shapefile 
## Source: "../data_processingScripts/municipios_2010", layer: "municipios_2010"
## with 5564 features
## It has 7 fields
## Integer64 fields read as strings:  id
### correct ibg codes (like FIPS)
# the ibg codes in the shapefile have an extra digit at the end, so we just subset the first six digits from the shapefile

brazil@data$muni.no <- as.numeric(as.character(substr(brazil@data$codigo_ibg,1,6)))

Map of Number of Cases per Muni from 2001-2014

# calculate total cases per muni
totCase <- YF %>%
  filter(cal.month<13) %>%
  group_by(muni.no) %>%
  summarise(totalCases=sum(case, na.rm=T))

# add to shapefile
brazilYF <- merge(brazil, totCase, by="muni.no")
#create color palette
colpal <- colorNumeric("Set1", domain = c(1,44))
#create popups
casePop <- paste0(brazilYF@data$nome, 
                      "<br><strong>", brazilYF@data$totalCases,
                  "</strong> Cases from 2001-2014.")
leaflet(data=brazilYF) %>%
  addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.75,
    fillColor = ~colpal(totalCases),
    highlightOptions = highlightOptions(color = "white", weight = 2,
      bringToFront = TRUE),
    popup=casePop) %>%
  addProviderTiles(providers$CartoDB.Positron)
## Warning in colpal(totalCases): Some values were outside the color scale and
## will be treated as NA

Map of the Spread of YF

This map will have a different color for each year.

#merge years with cases to shapefile
yearCase <- YF %>%
  select(-muni) %>%
  filter(cal.month<13) %>%
  filter(case>0) %>%
  #get the last time they had a case
  group_by(muni.no) %>%
  filter(month.no==max(month.no))

brazilYFtime <- merge(brazil, yearCase, by="muni.no", all.y=T)

yearColor <- colorBin(palette= "RdYlBu", domain=c(2001,2014))